<?php
namespace Bojin\Controller;
use Think\Controller;
use Bojin\Logic\UserLogic;
class RbacController extends BaseController {

	public function rbanmenu()
	{
	}
	public function rbacadd()
	{
		$resd=M('ChannelAdmin')->select();
		$channel=M('channel')->select();
		$this->assign('channel',$channel);
		$this->assign('data',$resd);
		$this->display('main_info');
	}
	public function adminlist()
    {
        $where = "1 = 1";
        $admin_name = I("post.admin_name");
        if(!empty($admin_name)){
             $where.=" and admin_name like '%".$admin_name."%'";
        }
        $p=I('post.p')?I('post.p'):1;
        $size=10;
        $page_set=($p-1)*$size;
        $count = M('ChannelAdmin')->where($where)->count();// 查询满足要求的总记录数
        $page_num=ceil($count/$size);//总页数
        $data=M('ChannelAdmin')->where($where)->limit($page_set,$size)->select();
        foreach ($data as $key => &$vo) {
            $vo['channel_name']=D('Customer')->numbergetname($vo['channel_id']);
        }
        $this->assign('page_num',$page_num);
        $this->assign('p',$p);
        $this->assign('admin_name',$admin_name);
        $this->assign('data',$data);
        $this->assign('num',$count);
        $this->assign('admin_name',$admin_name);
        $this->display('main_list');
    }
	public function adminadd()
	{
		$data=I("post.");
		if(!$data)
		{
			$this->error("不能为空");
		}
		if($data['power_id']==1&&empty($data['channel_id']))
		{
			$this->error("渠道不能为空");
		}
		if($data['admin_powd']!=$data['admin_repowd'])
		{
			$this->error("两次密码输入不一致");
		}
		$data['admin_powd']=md5($data['admin_powd']);
		$data['add_time']=time();
		$resd=M('ChannelAdmin')->add($data);
		if($resd)
		{
			$this->success("添加成功",U("Rbac/adminlist"),2);
		}
	}
	public function adminsave()
	{
		$data['admin_name']=I('post.name');
		$data['admin_powd']=md5(I('post.powd'));
		$data['channel_id']=I('post.channel');
		$resd=M('ChannelAdmin')->add($data);
		if($resd)
		{
			echo "ok";die;
		}
	}
	public function userinfo()
	{
		$data=session('user');
		echo $data['power_id'];
	}
	public function channeluser()
	{
        // dump(I());
		$p=I('post.p') ? I('post.p'):1;
		$channel=I('post.channel');
		$search=I('post.search');

		if($this->user['power_id']==0){
			$result=D('channel')->select();
			$where = '1=1';
			if(!empty($channel))
			{
				$where = 'channel_id = '."'$channel'";
			}
			$start=strtotime($search);
			$end=$start+24*3600;
			if(empty($search)||$search=='undefined')
			{

			}else
			{
				$where.=' and add_time between '."'$start'".' and '."'$end'";
			}
			$this->assign('arrd',$result);
			$size=10;
			$page_set=($p-1)*$size;
			$data['count'] = M('customer')->where($where)->count();// 查询满足要求的总记录数
			$data['page_num']=ceil($data['count']/$size);
			$data['user_data']=M('customer')->field('id,mobile,channel_id,id_num,add_time,gender')->where($where)->limit($page_set,$size)->select();
			foreach ($data['user_data'] as $k => &$v) {
       				$v['card_num'] = substr($v['id_num'],0,4).'**********'.substr($v['id_num'],-4);
      			}
		}else{  
			$res_du = $this->usershow($p,$search);
			$data['user_data']=$res_du['list'];
			$data['count'] = $res_du['count'];
			$data['page_num'] = $res_du['page_num'];
			$page = $res_du['page'];
			$time_du = strtotime(date('Ymd'));
			$data['parent'] = [
				date('Y-m-d'),
				date('Y-m-d',$time_du - 86400)
			];

			$this->assign('pages',$page);
		}
		$this->assign('page_num',$data['page_num']);

		$this->assign('p',$p);
		!empty($this->user['channel_id'])&&$userchannel=M('channel')->where('channel_number = '."'{$this->user['channel_id']}'")->find();
		$this->assign('channel',$userchannel);
		$this->assign('nowchannel',$channel);
		$this->assign('num',$data['count']);
		$this->assign('power',$this->user['power_id']);
		$this->assign('data',$data['user_data']);
		$this->assign('parent',$data['parent']);
		$this->assign('search',$search);
		$this->assign('page',$search);
		//print_r($userchannel);die;
		$this->display();
	}
	//渠道添加
	public function channeladd()
	{
		//$this->error('渠道连接在开发');die;
		if(IS_POST)
		{
			$data=I('post.');
			$channel=$data['channel_number'];
			$only=M('channel')->where('channel_number = '."'$channel'")->find();
			if($only)
			{
				echo $this->error('渠道号重复');
			}
			$data['channel_time']=time();
			$resd=M('channel')->add($data);
			if($resd)
			{
				$this->success("添加成功",U("Rbac/channellist"),2);die;
			}
		}
		$this->display();
	}
	//渠道列表
        public function channellist()
        {
            $p = I("post.p") ? I("post.p"):1;
            $up = I("post.up");
            if($up){
              $where["status"] = $up;
            }
            $qudao = I("post.qudao");
            if($qudao){
                $where["channel_name"] = array("like" , "%$qudao%");
                $this->assign("qudao",$qudao);
            }
            $size = 10;
            $page_set = ($p-1)*$size;
            $count = M('channel')->where($where)->count();// 查询满足要求的总记录数
            $page_num = ceil($count/$size);
            $result = M('channel')->limit($page_set,$size)->where($where)->order("status asc,channel_id asc")->select();
            $this->assign("up",$up);
            $this->assign('page_num',$page_num);
            $this->assign('p',$p);
            $this->assign('data',$result);
            $this->assign('num',$count);
            $this->display();

        }
	//生成推广链接
	public function getjsonlink()
	{
		$channel=I('get.channel');
		//$link='http://h5loan.minfujr.cn/pages/register/register.html?invent_id=&channel_id='.$channel;
		//$link='http://api.fenqingbang.com/h5/register/rigister.html?invent_id=&channel_id='.$channel;;
                $link = 'http://api.fenqingbang.com/h5/register/register_hmg.html?invent_id=&channel_id='.$channel;
		$url='http://api.t.sina.com.cn/short_url/shorten.json?url_long='.urlencode($link).'&source='.'1371787670';
		  //初始化
      $curl = curl_init();
      //设置抓取的url
      curl_setopt($curl, CURLOPT_URL, $url);
      //设置头文件的信息作为数据流输出
     	curl_setopt($curl, CURLOPT_HEADER, 0);
     //设置获取的信息以文件流的形式返回，而不是直接输出。
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      //执行命令
     $data = curl_exec($curl);
     //关闭URL请求
     curl_close($curl);
     //显示获得的数据
     $data=json_decode($data);
     if($data[0]->type==0)
     {
     	echo $data[0]->url_short;
 	}


	}
	//渠道注册列表
	public function channelshow()
	{
            $data = array();
            $nowtime = time();//获取当前时间
            if(I("post.search")){
                $search = I("post.search");
                $beginToday = strtotime($search);
                $endToday = strtotime($search)+24*60*60-1;
                $data['todaytime'] = $search;//获取今日时间
            }else{
                $data['todaytime'] = date("Y-m-d",$nowtime);//获取今日时间
                $beginToday = mktime(0,0,0,date('m'),date('d'),date('Y'));//获取今日开始时间
                $endToday = mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;//获取今日结束时间
            }
            $p = I('post.p') ? I('post.p') :1;
            $page_count = D('channel')->where("status = 1")->count();
            $page_count=$page_count+1;
            $size = 12;
            $page_set = ($p-1)*$size;
            
            //获取所有渠道
            $channel = M('channel')
                    ->field("channel_id,channel_number,channel_name")
                    ->where("status = 1")
                    ->limit($page_set,$size)
                    ->select();
            //获取所有今日注册用户以及用户相对应的各种认证
            $custmer = M("customer")
                    ->join("fb_customer_auth as f on f.customer_id = fb_customer.id")
                    ->field("fb_customer.id,channel_id,f.id_num,f.face_pass,f.china_mobile,"
                            . "f.bankcard_pass,login_time,f.userdetail_pass")
                    ->where('fb_customer.add_time between '."'$beginToday'".' and '."'$endToday'")
                    ->select();
            //获取今天所有的下款用户
            $iou = M("iou")
                    ->join("fb_customer as c on c.id = fb_iou.borrow_person_id")
                    ->field("fb_iou.channel_id")
                    ->where('iou_type = 1 and fb_iou.status in (1,4) and fb_iou.add_time '
                            . 'between '."'$beginToday'".' and '."'$endToday'" .' and '
                            . 'c.add_time between '."'$beginToday'".' and '."'$endToday'")
                    ->select();

            //获取今天老用户下款用户
            $oldiou = M("iou")
                    ->field("channel_id")
                    ->where('iou_type = 1 and status in (1,4) and add_time '
                            . 'between '."'$beginToday'".' and '."'$endToday'")
                    ->select();
            //获取渠道所有的下款用户
            $alliou = M("iou")
                    ->field("channel_id")
                    ->where('iou_type = 1 and status = 1')
                    ->select();
            //获取今天所有通过风控的人数
            $riskapply = M("RiskApply")
                    ->join("fb_customer as c on c.id = fb_risk_apply.customer_id","left")
                    ->field("customer_id,channel_id")
                    ->where("result = 'APPROVE' and fb_risk_apply.add_time between "."'$beginToday'".' and '."'$endToday'" .' and c.add_time between '."'$beginToday'".' and '."'$endToday'")
                    ->select();
            //获取今天老用户通过风控的人数
            $oldriskapply = M("RiskApply")
                    ->field("customer_id")
                    ->where("result = 'APPROVE' and add_time between "."'$beginToday'".' and '."'$endToday'")
                    ->select();
            //获取交服务费的
            $service = M('recharge')
                    ->join("fb_customer as c on c.id = fb_recharge.customer_id")
                    ->field("customer_id,channel_id")
                    ->where('fb_recharge.pay_time between '."'$beginToday'".' and '."'$endToday'" .' and '
                            . 'fb_recharge.order_type = 7 and fb_recharge.status = 1 and '
                            . 'fb_recharge.pay_status = 1 and c.add_time between '."'$beginToday'".' and '."'$endToday'")
                    ->select();
            //获取老用户交服务费的
            $oldservice = M('recharge')
                    ->field("customer_id")
                    ->where('pay_time between '."'$beginToday'".' and '."'$endToday'" .' and '
                            . 'order_type = 7 and status = 1 and '
                            . 'pay_status = 1')
                    ->select();
//            //获取逾期1-4，4天以上
//            $overdue_iou = M("iou")
//                    ->field("channel_id,actual_repayment_date")
//                    ->where("status = 1 and iou_type = 1 and overdue_status =1")
//                    ->select();
//            //转换成具体天数
//            foreach ($overdue_iou as $ko => $vo) {
//                $overdue_iou[$ko]['day'] = floor(($nowtime-$vo['actual_repayment_date']) / 86400);
//            }
//            foreach ($overdue_iou as $ko => $vo) {
//                if($vo['day'] < 4){
//                    $overdue_iou[$ko]['m1'] = 1;//获取逾期不超过四天的
//                }else{
//                    $overdue_iou[$ko]['m2'] = 1;//获取逾期等于超过四天的
//                }
//            }
            $data['count'] = count($custmer);//获取今日注册用户数量
            $data['debit'] = count($iou);//获取今日下款用户数量
            $data['olddebit'] = count($oldiou) - $data['debit'];//获取今日老用户下款用户数量
            $data['riskapply'] = count($riskapply);//获取今日所有通过风控人数
            $data['oldriskapply'] = count($oldriskapply) - $data['riskapply'];//获取今日老用户通过风控用户数量
            $data['service'] = count($service);//获取今日所有付款人数
            $data['oldservice'] = count($oldservice) - $data['service'];//获取今日老用户通过风控用户数量
            $data['conversion'] = floor($data['debit'] / $data['count'] * 100);//获取下款转化率
            foreach ($channel as $k => $v) {
                foreach ($custmer as $key => $val) {
                    if($v['channel_number'] == $val['channel_id']){
                        if($val['login_time'] > 1){
                            $channel[$k]['logincount'] += 1;//获取今日注册登陆用户
                        }
                        $channel[$k]['add_nums'] += 1;//获取今日注册用户
                        $channel[$k]['id_nums'] += $val['id_num'];//获取身份证认证
                        $channel[$k]['face_pass'] += $val['face_pass'];//扫脸活体检测
                        $channel[$k]['userdetail_pass'] += $val['userdetail_pass'];//紧急联系人
                        $channel[$k]['china_mobile'] += $val['china_mobile'];//运营商认证
                        $channel[$k]['bankcard_pass'] += $val['bankcard_pass'];//绑定银行卡
                    }
                }
                foreach ($iou as $ki => $vi) {
                    if($v['channel_number'] == $vi['channel_id']){
                        $channel[$k]['conversion_nums'] += 1;//获取今日注册下款用户数量
                    }
                }
                foreach ($alliou as $ka => $va) {
                    if($v['channel_number'] == $va['channel_id']){
                        $channel[$k]['alliou'] += 1;//获取今日注册下款用户数量
                    }
                }
                foreach ($riskapply as $kr => $vr) {
                    if($v['channel_number'] == $vr['channel_id']){
                        $channel[$k]['riskapply'] += 1;//获取今日通过风控人数
                    }
                }
                foreach ($service as $ks => $vs) {
                    if($v['channel_number'] == $vs['channel_id']){
                        $channel[$k]['service'] += 1;//获取今日付款人数
                    }
                }
                foreach ($overdue_iou as $ko => $vo) {
                    if($v['channel_number'] == $vo['channel_id']){
                        $channel[$k]['m1'] += $vo['m1'];
                        $channel[$k]['m2'] += $vo['m2'];
                    }
                }
            }
            foreach ($channel as $k => $v) {
                $channel[$k]['conversion_person'] = floor($v['conversion_nums'] / $v['add_nums'] * 100);
                $channel[$k]['pay_num'] = floor($v['service'] / $v['add_nums'] * 100);
//                $channel[$k]['m1'] = floor($v['m1'] / $v['alliou'] * 100);
//                $channel[$k]['m2'] = floor($v['m2'] / $v['alliou'] * 100);
                
            }
    /****************自然渠道流量统计()********************/
            $winfo=[];
            //获取所有没有渠道链接的渠道id
            $wchanne1id = M('channel')
                ->field("channel_number")
                ->where("channel_link is null or channel_link=''")
                ->select();
            foreach ($wchanne1id as $k=>$v){
                $channelid[]=$v['channel_number'];
            }
            $where = "fb_customer.channel_id in ('".join("','",$channelid)."')";

//            获取所有今日注册用户以及用户相对应的各种认证
            $custmerreg = M("customer")
                ->join("fb_customer_auth as f on f.customer_id = fb_customer.id")
                ->field("fb_customer.id,f.id_num,f.face_pass,f.china_mobile,"
                    . "f.bankcard_pass,login_time,f.userdetail_pass")
                ->where('fb_customer.add_time between '."'$beginToday'".' and '."'$endToday'".' and '.$where)
                ->select();

            //获取今天所有的下款用户
            $where1 = "c.channel_id in ('".join("','",$channelid)."')";
            $allxk = M("iou")
                ->join("fb_customer as c on c.id = fb_iou.borrow_person_id")
                ->field("fb_iou.channel_id")
                ->where('fb_iou.iou_type = 1 and fb_iou.status in (1,4) and fb_iou.add_time '
                    . 'between '."'$beginToday'".' and '."'$endToday'" .' and '
                    . 'c.add_time between '."'$beginToday'".' and '."'$endToday'".' and '.$where1)
                ->select();

            //获取今日注册登陆用户
            foreach($custmerreg as $k=>$v){
                if($v['login_time']>1){
                    $winfo['logincount'] += 1;
                    $winfo['id_nums'] += $v['id_num'];//获取身份证认证
                    $winfo['face_pass'] += $v['face_pass'];//扫脸活体检测
                    $winfo['userdetail_pass'] += $v['userdetail_pass'];//紧急联系人
                    $winfo['china_mobile'] += $v['china_mobile'];//运营商认证
                    $winfo['bankcard_pass'] += $v['bankcard_pass'];//绑定银行卡
                }
            }
            //获取今天所有通过风控的人数
            $wriskapply = M("RiskApply")
                ->join("fb_customer as c on c.id = fb_risk_apply.customer_id","left")
                ->field("customer_id,channel_id")
                ->where("fb_risk_apply.result = 'APPROVE' and fb_risk_apply.add_time between "."'$beginToday'".' and '."'$endToday'" .' and c.add_time between '."'$beginToday'".' and '."'$endToday'".' and '.$where1)
                ->select();
            //获取交服务费的
            $wservice = M('recharge')
                ->join("fb_customer as c on c.id = fb_recharge.customer_id")
                ->field("customer_id,channel_id")
                ->where('fb_recharge.pay_time between '."'$beginToday'".' and '."'$endToday'" .' and '
                    . 'fb_recharge.order_type = 7 and fb_recharge.status = 1 and '
                    . 'fb_recharge.pay_status = 1 and c.add_time between '."'$beginToday'".' and '."'$endToday'".' and '.$where1)
                ->select();

            $winfo['wservice']=count($wservice); //获取今日付款人数
            $winfo['wriskapply']=count($wriskapply);//获取今天所有通过风控的人数
            $winfo['count']=count($custmerreg);//当日注册数量
            $winfo['allxk']=count($allxk);//今天所有的下款用户数量
            $winfo['cvr']=floor($winfo['allxk'] / $winfo['count'] * 100);//获取下款转化率
            $winfo['wpay_num']=floor($winfo['wservice'] / $winfo['count'] * 100); //获取付款转化率


            $page_num=ceil($page_count/$size);
            $this->assign('num',$page_count);
            $this->assign('page_num',$page_num);
            $this->assign('p',$p);
            $this->assign('data',$channel);
            $this->assign('info',$data);
            $this->assign('search',$search);
            $this->assign('page',$search);
            $this->assign('winfo',$winfo);
            $this->display();
	}
	public function getoverday($id)
	{
		$customer_id=M('customer')->field('id')->where('channel_id = '."'$id'")->select();
			foreach ($customer_id as $key => $v) {
				$data.=','.$v['id'];
			}
			$dataarr=substr($data,1);
			empty($dataarr)&&$dataarr="''";
			$data=M('iou')->where('borrow_person_id in ( '.$dataarr.')')->select();
			$count=count($data);
			//$data='';
			$list=[];
		foreach($data as $k=>$v){
					//逾期天数计算
					if($v['status'] == 4){
						$time_s = date('Ymd',$v['repayment_time']);
					}else{
						$time_s = date('Ymd',time());
					}
					$time_e = date('Ymd',$v['borrow_end_time']);
					$over_time = floor((strtotime($time_s) - strtotime($time_e))/86400);
					if($over_time>0&&$over_time<5)
					{
						$list[] = $over_time;
					}
					if($over_time>4)
					{
						$arrd[] = $over_time;
					}
				}
				$all['M1']=floor(count($list)/$count*100);
				$all['M2']=floor(count($arrd)/$count*100);
				return $all;
	}
	public function channeltedails()
	{
		$id=I('get.channel');
		$resd=M('channel')->where('channel_id = '.$id)->find();
		$over=$this->getoverday($id);
		$resd['M1']=$over['M1'];
		$resd['M2']=$over['M2'];
		print_r($resd);die;
		$this->display();
	}
	//过滤
	public function usershow($p,$search){
		$user=session('user');

		//渠道ID
		$channel_id=$user['channel_id'];

		//查询最后查询的时间
		$time_ch = M('channel_date')->where(['channel_id'=>$channel_id])->find();

		$time_end_du = $time_ch['srcipt_date'] + 600;

		if(time() > $time_end_du){

			if($time_ch['srcipt_date']){

				$where['channel_id'] = $channel_id;
				$where['add_time'] = ['gt',$time_ch['srcipt_date']];

				$customer_list = M('customer')->field('id as customer_id,add_time,gender,id_num,user_id')->where($where)->order('add_time desc')->select();

				//查询扣量比例
				$adjust = M('channel')->field('adjust')->where(['channel_number'=>$channel_id])->find();

				if($adjust['adjust'] != 0){

					$count = count($customer_list);
					//扣量计算
					$num = ceil($count / ($count * ($adjust['adjust'] / 100)));

					for($i=0;$i<$count;$i++){
						if(($i%$num) == 0){
							unset($customer_list[$i]);
							continue;
						}
						$customer_list[$i]['channel_id'] = $channel_id;
					}


				}else{
					foreach($customer_list as $k=>$v){
						$customer_list[$k]['channel_id'] = $channel_id;
					}
					
				}
				
				if($customer_list){
                                    //添加所有数据
                                    $sql = "insert into fb_channel_reduce(channel_id,add_time,id_num,customer_id,user_id,gender) VALUES";
                                    foreach ($customer_list as $kc => $vc) {
                                        $sql .= "({$vc['channel_id']} , {$vc['add_time']} , '{$vc['id_num']}' ,{$vc['customer_id']} , {$vc['user_id']} , '{$vc['gender']}'),";
                                    }

                                    $sql = trim($sql,',');
                                    $return = M("ChannelReduce")->execute($sql);
                                    
                                    //更新最后记录时间
                                    M('channel_date')->where(['channel_id'=>$channel_id])->save(['srcipt_date'=>time()]);
                                }

			}else{
				$customer_list = M('customer')->field('id as customer_id,add_time,gender,id_num,user_id')->where(['channel_id'=>$channel_id])->order('add_time desc')->select();

				if($customer_list){
					foreach($customer_list as $k=>$v){
						$customer_list[$k]['channel_id'] = $channel_id;
					}
                                        //添加所有数据
                                        $sql = "insert into fb_channel_reduce(channel_id,add_time,id_num,customer_id,user_id,gender) VALUES";
                                        foreach ($customer_list as $kc => $vc) {
                                            $sql .= "({$vc['channel_id']} , {$vc['add_time']} , '{$vc['id_num']}' ,{$vc['customer_id']} , {$vc['user_id']} , '{$vc['gender']}'),";
                                        }

                                        $sql = trim($sql,',');
                                        $return = M("ChannelReduce")->execute($sql);
				}

				M('channel_date')->add(['srcipt_date'=>time(),'channel_id'=>$channel_id]);
			}
		}
		//输出数据给用户
		if($search){
			$time_c_s = strtotime($search);
			$time_c_e = $time_c_s + 86399;
			$where_c['add_time'] = ['between',[$time_c_s,$time_c_e]];
		}else{

			$time_c_s = strtotime(date('Ymd'));
			$time_c_e = $time_c_s + 86399;
			$where_c['add_time'] = ['between',[$time_c_s,$time_c_e]];
		}


		$where_c['channel_id'] = $channel_id;

		$count_list = M('channel_reduce')->where($where_c)->count();
		$page = $this->getpage($count_list,10);
		$show = $page->show();
		$list = M('channel_reduce')->where($where_c)->order('user_id desc')->limit($page->firstRow.','.$page->listRows)->select();

		

		$channel_reduce_list = array_column($list,'user_id');
		if($channel_reduce_list){
			$mobile = new UserLogic();
			$mobile_list = $mobile->getmobileall($channel_reduce_list);
			foreach($list as $k=>$v){
				$list[$k]['mobile'] = substr($mobile_list[$k]['mobile'],0,3).'******'.substr($mobile_list[$k]['mobile'],-2);
				if($list[$k]['id_num'] != ''){
					$list[$k]['card_num'] = substr($list[$k]['id_num'],0,3).'************'.substr($list[$k]['id_num'],-3);	
				}
			}
		}
		//获取手机号码,最终整合

		return ['list'=>$list,'page'=>$show,'count'=>$count_list];
	}


	/**
	 * [adjust 扣量百分比ajax请求]
	 * @return [type] [description]
	 */
	public function adjust(){
		if(IS_POST){
			$data = I('post.');
			if(!$data['id']){
				$this->ajaxReturn(['code'=>0,'msg'=>'非法请求']);
			}

			$res = M('channel')->where(['channel_id'=>$data['id']])->save(['adjust'=>$data['adjust']]);

			if($res){
				$this->ajaxReturn(['code'=>1,'msg'=>'修改成功!']);
			}else{
				$this->ajaxReturn(['code'=>0,'msg'=>'修改失败,请稍后重试!']);
			}
		}
	}





	/**
	 * [getpage 分页样式-勿动]
	 * @param  [type]  $count    [description]
	 * @param  integer $pagesize [description]
	 * @return [type]            [description]
	 */
	public function getpage($count, $pagesize = 10) {
	    $p = new \Think\Page($count, $pagesize);
	    $p->setConfig('header', '<li class="rows">共<b>%TOTAL_ROW%</b>条记录 第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
	    $p->setConfig('prev', '上一页');
	    $p->setConfig('next', '下一页');
	    $p->setConfig('last', '末页');
	    $p->setConfig('first', '首页');
	    $p->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');
	    $p->lastSuffix = false;//最后一页不显示为总页数
	    return $p;
	}
    /**
     * [statusAll 渠道上下线]
     * @author lxl 2018 09 26
     * @param  [type]  pids    [id]
     * @param  integer status  [1 上线   2下线]
     * @return [type] [true or false]
     */
    public function statusAll(){
        if(IS_POST){
            $postData = I("post.");
            if($postData["pid"]){
                 $id = explode(",", $postData["pid"]);
                 $model = M("channel");
                 foreach ($id as $key => $val) {
                    $save["status"] = $postData["status"];
                    $model -> where("channel_id = $val") -> save($save);
                 }
                 $msg["code"] = 1;
                 $msg["msg"]  = "ok";
              }else{
                $msg["code"] = 2;
                $msg["msg"]  = "请选择渠道！";
              }
        }else{
            $msg["code"] = 2;
            $msg["msg"]  = "非法请求！";
        }
        $this -> ajaxReturn($msg);
    }
}